package com.qiangesoft.blog.controller.manage;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.qiangesoft.blog.common.annotation.OperationLog;
import com.qiangesoft.blog.common.mvc.PageQuery;
import com.qiangesoft.blog.common.mvc.PageResultVO;
import com.qiangesoft.blog.common.result.ResponseResult;
import com.qiangesoft.blog.system.entity.SysDict;
import com.qiangesoft.blog.system.service.ISysDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @author qiange
 */
@RestController
@RequestMapping("/system/dict")
@Api(tags = "字典类型管理")
@RequiredArgsConstructor
public class SysDictController {

    private final ISysDictService dictService;

    @GetMapping(value = "/list")
    @ApiOperation(value = "字典类型列表")
    public PageResultVO<SysDict> list(PageQuery pageQuery, String name, Boolean isPublish, String descColumn, String ascColumn) {
        return dictService.listDict(pageQuery, name, isPublish, descColumn, ascColumn);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation(value = "添加字典", httpMethod = "POST", response = ResponseResult.class, notes = "添加字典")
    @OperationLog(value = "添加字典")
    public void insert(@RequestBody SysDict dict) {
        dictService.insertDict(dict);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改字典", httpMethod = "POST", response = ResponseResult.class, notes = "修改字典")
    @OperationLog(value = "修改字典")
    public void update(@RequestBody SysDict dict) {
        dictService.updateDict(dict);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除字典", httpMethod = "DELETE", response = ResponseResult.class, notes = "删除字典")
    @OperationLog(value = "删除字典")
    public void deleteDict(Long id) {
        dictService.deleteDict(id);
    }

    @RequestMapping(value = "/deleteBatch", method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除字典", httpMethod = "DELETE", response = ResponseResult.class, notes = "批量删除字典")
    @OperationLog(value = "批量删除字典")
    public void deleteBatch(@RequestBody List<Long> list) {
        dictService.deleteBatch(list);
    }
}

